package com.example.transactionhintassistant.controller;

import com.example.transactionhintassistant.pojo.weeklyplan.AddTaskByWeeklyPlanDto;
import com.example.transactionhintassistant.service.WeeklyPlansService;
import com.example.transactionhintassistant.utils.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/weekly-plan")
@Tag(name = "6.周计划模块")
public class WeeklyPlanController {
    @Autowired
    private WeeklyPlansService weeklyPlansService;

    @GetMapping("/list")
    @Operation(summary = "获取个人周计划列表", security = {@SecurityRequirement(name = "Authorization")})
    public Result<Object> getWeeklyPlans()
    {
        return weeklyPlansService.getWeeklyPlans();
    }

    @PostMapping("/add/{planName}")
    @Operation(summary = "增加个人周计划", security = {@SecurityRequirement(name = "Authorization")})
    public Result<Object> addWeeklyPlan(@PathVariable String planName)
    {
        return weeklyPlansService.addWeeklyPlan(planName);
    }

    @PutMapping("/change-name/{id}/{planName}")
    @Operation(summary = "修改周计划名", security = {@SecurityRequirement(name = "Authorization")})
    public Result<Object> changeWeeklyPlanName(@PathVariable int id , @PathVariable String planName)
    {
        return weeklyPlansService.changeWeeklyPlanName(id, planName);
    }

    @DeleteMapping("/delete/{id}")
    @Operation(summary = "删除周计划")
    public Result<Object> deleteWeeklyPlan(@PathVariable int id)
    {
        return weeklyPlansService.deleteWeeklyPlan(id);
    }

    @PostMapping("/addTask")
    @Operation(summary = "增加周计划事务", security = {@SecurityRequirement(name = "Authorization")})
    public Result<Object> addTaskByWeeklyPlan(@RequestBody @Validated AddTaskByWeeklyPlanDto addTaskByWeeklyPlanDto)
    {
        return weeklyPlansService.addTaskByWeeklyPlan(addTaskByWeeklyPlanDto);
    }

    @GetMapping("/getIdByName/{planName}")
    @Operation(summary = "根据名称获取周计划id", security = {@SecurityRequirement(name = "Authorization")})
    public Result<Object> getWeeklyPlanIdByName(@PathVariable String planName)
    {
        return weeklyPlansService.getWeeklyPlanIdByName(planName);
    }

    @GetMapping("/task-list/{id}")
    @Operation(summary = "获取周计划下的事务", security = {@SecurityRequirement(name = "Authorization")})
    public Result<Object> getTaskFromWeeklyPlan(@PathVariable int id)
    {
        return weeklyPlansService.getTaskFromWeeklyPlan(id);
    }



}
